package com.baiyun.service.impl;

import com.baiyun.entity.Sale;
import com.baiyun.mapper.SalesMapper;
import com.baiyun.service.SalesService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.List;

@Service
@RequiredArgsConstructor
public class SalesServiceImpl implements SalesService {
    private final SalesMapper salesMapper;

    /**
     * 查询所有销售记录
     * @return
     */
    @Override
    public List<Sale> selectAllSales() {
        return salesMapper.selectAllSales();
    }

    /**
     * 添加销售记录
     * @param sale
     */
    @Override
    public void addSales(Sale sale) {
        sale.setTime(new Date(System.currentTimeMillis()));
        salesMapper.addSales(sale);
    }

    /**
     * 更新销售记录
     * @param sale
     */
    @Override
    public void updateSales(Sale sale) {
        sale.setTime(new Date(System.currentTimeMillis()));
        salesMapper.updateSales(sale);
    }

    /**
     * 删除销售记录
     * @param sid
     */
    @Override
    public void deleteSales(Integer sid) {
        salesMapper.deleteSales(sid);
    }

    /**
     * 通过id查询销售记录
     * @param sid
     * @return
     */
    @Override
    public Sale getSaleById(Integer sid) {
        return salesMapper.getSaleById(sid);
    }

    /**
     *  根据名称查询销售记录
     * @param name
     * @return
     */
    @Override
    public List<Sale> selectByName(String name) {
        return salesMapper.selectByName(name);
    }
}
